package cmd

import (
	"card/bootstrap"
	"card/config"
	"card/pkg/tconfig"
	"github.com/spf13/cobra"
	"log"
)

// go run main.go server --env=local
var RootCmd = &cobra.Command{
	Use:   "card",
	Short: "A simple forum project",
	Long:  `Default will run "server" command, you can use "-h" flag to see all subcommands`,
	// rootCmd 的所有子命令都会执行以下代码
	PersistentPreRun: func(command *cobra.Command, args []string) {
		log.Printf("Inside rootCmd PersistentPreRun with args: %v\n", args)
		tconfig.InitConfig("./conf", Env)
		err := tconfig.Unmarshal(&config.Application)
		if err != nil {
			log.Printf("解析配置文件错误: %v\n", err)
		}
		config.Application.Server.AppEnv = Env
		bootstrap.SetupLogger()
		bootstrap.SetUpDb()
		bootstrap.SetupRedis()
		bootstrap.SetupCache()
	},
}
